// src/api/user.js
import axios from 'axios';

const API_BASE = '/teach';

export const userApi = {
  // 获取用户列表 - 对应后端 GET /auth/list
  getUsers: (params = {}) => {
    return axios.get(`${API_BASE}/auth/list`, { params });
  },

  // 注册用户 - 对应后端 POST /auth/register
  registerUser: (userData) => {
    return axios.post(`${API_BASE}/auth/register`, userData);
  },

  // 更新用户 - 对应后端 PUT /auth/update/{id}
  updateUser: (id, userData) => {
    return axios.put(`${API_BASE}/auth/update/${id}`, userData);
  },

  // 删除用户 - 对应后端 DELETE /auth/delete/{id}
  deleteUser: (id) => {
    return axios.delete(`${API_BASE}/auth/delete/${id}`);
  },

  // 用户登录 - 对应后端 POST /auth/login
  login: (credentials) => {
    return axios.post(`${API_BASE}/auth/login`, credentials);
  }
};

export const permissionApi = {
  // 新增角色 - 对应后端 POST /permission/add-role
  addRole: (roleData) => {
    return axios.post(`${API_BASE}/permission/add-role`, roleData);
  },

  // 分配用户角色 - 对应后端 POST /permission/assign-user-role
  assignUserRole: (assignmentData) => {
    return axios.post(`${API_BASE}/permission/assign-user-role`, assignmentData);
  },

  // 新增权限 - 对应后端 POST /permission/add-permission
  addPermission: (permissionData) => {
    return axios.post(`${API_BASE}/permission/add-permission`, permissionData);
  },

  // 分配角色权限 - 对应后端 POST /permission/assign-role-permission
  assignRolePermission: (assignmentData) => {
    return axios.post(`${API_BASE}/permission/assign-role-permission`, assignmentData);
  }
};